ARG PHP_VERSION=5.6
FROM php:${PHP_VERSION}-fpm-alpine

LABEL maintainer="cwl<chenwenlong@epweike.com>"

# repositorie mirror、timezone
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories ; \
    apk add --no-cache --virtual .timezone-deps tzdata; \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ; \
    echo 'Asia/Shanghai' > /etc/timezone; \
    rm -rf /var/cache/apk/* /tmp/* /var/tmp/* /var/lib/apt/lists/*

RUN set -ex ; \
	apk add --no-cache --virtual .build-deps \
	    $PHPIZE_DEPS \
	    autoconf \
	    libaio-dev \
	    #openssl-dev \
	    imagemagick-dev \
	    freetype-dev \
	    icu-dev \
	    curl-dev \
	    git \
	    libxml2-dev \
	    libmemcached-dev \
		libjpeg-turbo-dev \
		libpng-dev; \
	docker-php-ext-configure gd --with-png-dir=/usr/include --with-jpeg-dir=/usr/include --with-freetype-dir=/usr/include/freetype2; \
	docker-php-ext-configure intl; \
	docker-php-ext-install gd mysqli opcache pdo_mysql zip intl exif pcntl bcmath; \
	pecl install redis-4.2.0; \
	pecl install memcached-2.2.0; \
	pecl install imagick-3.4.3; \
	docker-php-ext-enable redis memcached imagick;\
	runDeps="$( \
		scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
			| tr ',' '\n' \
			| sort -u \
			| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
	)"; \
	apk add --virtual .epwk-phpexts-rundeps $runDeps; \
	apk del .build-deps; \
	rm -rf /var/cache/apk/* /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/www/html

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
		echo 'opcache.memory_consumption=128'; \
		echo 'opcache.interned_strings_buffer=8'; \
		echo 'opcache.max_accelerated_files=4000'; \
		echo 'opcache.revalidate_freq=2'; \
		echo 'opcache.fast_shutdown=1'; \
		echo 'opcache.enable_cli=1'; \
	} > /usr/local/etc/php/conf.d/opcache-recommended.ini

COPY php5.6.ini /usr/local/etc/php/php.ini

#RUN apk --no-cache add shadow; \
#    usermod -u 1000 www-data

WORKDIR /var/www
